<template>
  <view class="tabs">
    <view
      class="tabs_item"
      v-for="(item,index) in tabsData"
      :key="item.id"
      :class="{active: activeIndex===index}"
      @tap="changeTabsIndex(index)"
    >{{ item.text }}</view>
  </view>
</template>

<script>
export default {
  props: ["tabsData"],
  data() {
    return {
      activeIndex: 0,
    };
  },
  methods: {
    changeTabsIndex(index) {
      // 改变索引让组件自己选中状态更新
      this.activeIndex = index;
      // 把当前组件内部索引传递给父组件
      this.$emit("change", index);
    },
  },
};
</script>

<style lang="less">
.tabs {
  display: flex;
  justify-content: space-evenly;
  .tabs_item {
    width: 184rpx;
    height: 88rpx;
    font-size: 30rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 3rpx solid transparent;
    &.active {
      font-weight: bold;
      border-bottom-color: #ea4350;
    }
  }
}
</style>